package org.springblade.project.service;

import lombok.extern.slf4j.Slf4j;
import org.springblade.core.ds.SQResult;
import org.springblade.core.etl.dao.EtlDao;
import org.springblade.core.etl.model.EtlRunVO;
import org.springblade.core.etl.service.EtlJob;
import org.springblade.core.etl.service.EtlJobManager;
import org.springblade.mes.log.entity.SyncRecord;
import org.springblade.mes.log.service.SyncRecordService;
import org.springblade.project.config.TestConfig;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 服务
 *
 * @Version 1.0
 */
@Slf4j
@Service
public class TestJob implements EtlJob {
    @Resource
    private SyncRecordService syncRecordService;
    @Resource
    private TestConfig testConfig;

    @PostConstruct
    public void init() {
        EtlJobManager.addJob("testJob", this, testConfig, 10);
    }

    @Override
    public void process(EtlRunVO info) {
        try {
            String sql = "select Code as code from TB_StationA where AccDate > '2025-05-22 11:55:00' order by AccDate desc ";
            List<Map<String, Object>> dataList = EtlDao.list(new SQResult().setSql(sql), testConfig);

            SyncRecord r;
            for (Map<String, Object> objectMap : dataList) {
                r = new SyncRecord();
                r.setBusinessType(objectMap.get("code").toString());
                syncRecordService.save(r);
            }


        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}

